/*
 * CriticalSection.cpp
 *
 *  Created on: 2012-10-15
 *      Author: tony
 */

#include "CriticalSection.h"

const DWORD DEFAULT_SPIN_COUNT = 0x400;

/**
 * Creates and initializes a critical section with a
 * default spin count.
 */
CriticalSection::CriticalSection()
: m_spin_count(DEFAULT_SPIN_COUNT)
{
	Initialize();
}

/**
 * Creates and initializes a critical section with a
 * specified spin count.
 */
CriticalSection::CriticalSection(DWORD spin_count)
: m_spin_count(spin_count)
{
	Initialize();
}

/**
 * Destructor
 */
CriticalSection::~CriticalSection()
{
	DeleteCriticalSection(&m_critical_section);
}

/**
 * Initializes the critical section.
 */
void CriticalSection::Initialize()
{
	InitializeCriticalSectionAndSpinCount(&m_critical_section, m_spin_count);
}
